package com.hutiao.snowhb.wechat.parser;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.hutiao.snowhb.wechat.vo.WxRecvEventGeo;
import com.hutiao.snowhb.wechat.vo.WxRecvMsg;

public class WxRecvEventGeoParser extends WxRecvMsgBaseParser {

	@Override
	protected WxRecvMsg parser(Element root, WxRecvMsg msg) throws JDOMException {
		String event = getElementText(root, "Event");
		String latitude = getElementText(root, "Latitude");
		String longitude = getElementText(root, "Longitude");
		String precision = getElementText(root, "Precision");
		
		return new WxRecvEventGeo(msg, event, parseDouble(latitude, 0.0), 
				parseDouble(longitude, 0.0), parseDouble(precision, 0.0));
	}
	
	private double parseDouble(String val,double def) {
		try {
			return Double.parseDouble(val);
		}catch(Exception e) {
			return def;
		}
	}

}
